package com.J.Plane;

import javax.microedition.khronos.opengles.GL10;

import junit.framework.Assert;

public class SceneManager {
	
	private Camera	mCamera;
	private SceneNode	mRootNode;
	
	
	/**
	 * CTOR
	 */
	public SceneManager() {
		mRootNode = new SceneNode("root");
	}
	
	public SceneManager camera(Camera cam) {
		mCamera = cam;
		return this;
	}
	public Camera camera() {
		return mCamera;
	}
	
	/**
	 * Add node.
	 * @param node
	 */
	public SceneManager addNode(SceneNode node) {
		Assert.assertNotNull(node);
		mRootNode.addChild(node);
		return this;
	}
	
	/**
	 * Remove child node
	 * @param node
	 * @return
	 */
	public SceneManager removeNode(SceneNode node) {
		Assert.assertNotNull(node);
		mRootNode.removeChild(node);
		return this;
	}
	
	
	/**
	 * Render scene
	 * @param [in]gl	OpenGL context
	 */
	public void renderScene(GL10 gl) {
		Assert.assertNotNull(mCamera);
		mCamera.setProjectionMatrix(gl);
		mCamera.setViewToWorldMatrix(gl);
		
		// Render whole tree
		mRootNode.render(gl);
	}
	
	/**
	 * Find node on tree
	 * @param name
	 * @return
	 */
	public SceneNode node(String name) {
		return mRootNode.searchNode(name);
	}
}


